package cn.bdqn.controller;

import cn.bdqn.pojo.Course;
import cn.bdqn.pojo.CourseType;
import cn.bdqn.pojo.Pltable;
import cn.bdqn.service.CourseService;
import cn.bdqn.service.CourseTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class CourseTypeController {
    @Autowired
    CourseTypeService courseTypeService;
    @Autowired
    CourseService courseService;
    //查询课程列表
    @RequestMapping("/lb")
    public String lb(Model model){
        //查询课程类型
        List<CourseType> list = courseTypeService.getList();
        model.addAttribute("list",list);
        //查询课程列表
        List<Course> list1 = courseService.getList2();
        model.addAttribute("list1", list1);
        return "kc";
    }
    //查询课程类型ID
    @RequestMapping("/couseid")
    @ResponseBody
    public List<Course> Courses(@RequestParam("id") Integer courseid) {
        List<Course> couseList = courseService.getList(courseid);
        return couseList;
    }
//查询课程详情
    @RequestMapping("/couseXq")
    public String Xq(@RequestParam("id") Integer courseid, Model model){
        //查询课程详情
        Course cousesList = courseService.getList3(courseid);
        model.addAttribute("lists1",cousesList);
        //查询评论
        List<Pltable> courseList = courseService.getList1(courseid);
        model.addAttribute("coures",courseList);
        return "project";

    }
    @RequestMapping("/couseSp")
    public String video(@RequestParam("id") Integer courseid, Model model){
        //查询课程视频
        Course videoList = courseService.getList4(courseid);
        model.addAttribute("lists2",videoList);
        //查询评论
        List<Pltable> courseList = courseService.getList1(courseid);
        model.addAttribute("coures",courseList);
        return "vedio1";
    }
//新增评论
    @RequestMapping("toadd")
    public String courseadd(){
        return "add";
    }

    @ResponseBody
    @RequestMapping("/addinfo")
    public String courseadd1(Pltable pltable){
        int i= courseService.add(pltable);
        System.out.println(i);
        if (i>0){

            return "1";
        }
        return "";
    }
}
